package org.csu.molediary.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.csu.molediary.api.common.CommonResponse;
import org.csu.molediary.api.entity.Account;
import org.csu.molediary.api.persistence.AccountMapper;
import org.csu.molediary.api.service.AdminAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("AdminAccountService")
public class AdminAccountServiceImpl implements AdminAccountService {
    @Autowired
    AccountMapper accountMapper;

    //查询所有account信息
    @Override
    public CommonResponse<List<Account>> getAllAccount() {
        List<Account> accounts=accountMapper.selectList(null);
        if (accounts!=null){
            return CommonResponse.createForAdminSuccess("",accounts);
        }
        else
            return CommonResponse.createForAdminSuccessMessage("找寻不到用户");
    }

    //删除某个Account信息
    @Override
    public CommonResponse<String> deleteAccountByAccountId(String accountid) {
        QueryWrapper<Account> accountQueryWrapper=new QueryWrapper<>();
        accountQueryWrapper.eq("id",accountid);
        Account account = accountMapper.selectOne(accountQueryWrapper);
        if(account==null){
            return  CommonResponse.createForAdminError("找不到该用户删除失败！");
        }
        accountMapper.delete(accountQueryWrapper);
        return CommonResponse.createForAdminSuccessMessage("删除成功");

    }

    @Override
    public CommonResponse<List<Account>> selectAccountById(String userid) {
        Account account=accountMapper.selectById(userid);
        List<Account> accountList = new ArrayList<>();
        accountList.add(account);
        if(account==null){
            CommonResponse.createForAdminError("没有找到该用户");
        }
        return CommonResponse.createForAdminSuccess("",accountList);
    }

    @Override
    public CommonResponse<Account>  updateAccountInformation(Account account) {
        int month = account.getMonth();
        int day = Integer.parseInt(account.getDate());
        String star = null;
        //通过出生日期计算星座
        switch (month) {
            case 1:
                star = day < 21 ? "摩羯座" : "水瓶座";
                break;
            case 2:
                star = day < 20 ? "水瓶座" : "双鱼座";
                break;
            case 3:
                star = day < 21 ? "双鱼座" : "白羊座";
                break;
            case 4:
                star = day < 21 ? "白羊座" : "金牛座";
                break;
            case 5:
                star = day < 22 ? "金牛座" : "双子座";
                break;
            case 6:
                star = day < 22 ? "双子座" : "巨蟹座";
                break;
            case 7:
                star = day < 23 ? "巨蟹座" : "狮子座";
                break;
            case 8:
                star = day < 24 ? "狮子座" : "处女座";
                break;
            case 9:
                star = day < 24 ? "处女座" : "天秤座";
                break;
            case 10:
                star = day < 24 ? "天秤座" : "天蝎座";
                break;
            case 11:
                star = day < 23 ? "天蝎座" : "射手座";
                break;
            case 12:
                star = day < 22 ? "射手座" : "摩羯座";
                break;

        }
        account.setStar(star);

        UpdateWrapper<Account> accountUpdateWrapper=new UpdateWrapper<>();
        accountUpdateWrapper.eq("id",account.getId());
        accountMapper.update(account,accountUpdateWrapper);

        return CommonResponse.createForAdminSuccess("",account);
    }
}
